﻿using System;
using Owin;

namespace Flickr.Owin.Security.Extensions
{

    public static class FlickrAuthenticationExtensions
    {
        /// <summary>
        /// Authenticate users using Flickr
        /// </summary>
        /// <param name="app">The <see cref="IAppBuilder"/> passed to the configuration method</param>
        /// <param name="options">Middleware configuration options</param>
        /// <returns>The updated <see cref="IAppBuilder"/></returns>
        public static IAppBuilder UseFlickrAuthentication(this IAppBuilder app, FlickrAuthenticationOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            app.Use(typeof(FlickrAuthenticationMiddleware), app, options);
            return app;
        }

        /// <summary>
        /// Authenticate users using Flickr
        /// </summary>
        /// <param name="app">The <see cref="IAppBuilder"/> passed to the configuration method</param>
        /// <param name="appKey">The appKey assigned by Flickr</param>
        /// <param name="appSecret">The appSecret assigned by Flickr</param>
        /// <returns>The updated <see cref="IAppBuilder"/></returns>
        public static IAppBuilder UseFlickrAuthentication(
            this IAppBuilder app,
            string appKey,
            string appSecret)
        {
            return UseFlickrAuthentication(
                app,
                new FlickrAuthenticationOptions
                {
                    AppKey = appKey,
                    AppSecret = appSecret,
                });
        }
    }
}
